package eazy;
import java.util.Arrays;

public class mergeTwoArrays_88 {
    public static void main(String[] args) {
        mergeTwoArrays_88 mergeTwoArrays_88 = new mergeTwoArrays_88();
        int[] a = new int[]{5, 6, 10};
        int[] b = new int[]{3};
        merge(a,3,b,1) ;
    }

    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        int p1 = 0, p2 = 0;
        int[] sorted = new int[m + n];
        int cur;
        while (p1 < m || p2 < n) {
            //如果p1到了边界
            if (p1 == m) {
                cur = nums2[p2++];
            //如果p2到了边界
            } else if (p2 == n) {
                cur = nums1[p1++];
            } else if (nums1[p1] < nums2[p2]) {
                cur = nums1[p1++];
            } else {
                cur = nums2[p2++];
            }
            sorted[p1 + p2 - 1] = cur;
        }
        System.out.println(Arrays.toString(sorted));
    }
}
